package com.zzyl.controller.customer;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.UserLoginRequestDto;
import com.zzyl.service.DeviceDataService;
import com.zzyl.service.DeviceService;
import com.zzyl.service.MemberService;
import com.zzyl.vo.DeviceDataGraphVo;
import com.zzyl.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "客户管理")
public class CustomerController extends BaseController {

    @Autowired
    private MemberService memberService;

    @Autowired
    private DeviceService deviceService;

    @Autowired
    private DeviceDataService deviceDataService;


    @PostMapping("/customer/user/login")
    public ResponseResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo =  memberService.login(dto);
        return ResponseResult.success(loginVo);
    }


    @PostMapping("/customer/user/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request ) {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData data = deviceService.queryDevicePropertyStatus(request);
        return ResponseResult.success(data);
    }


    @GetMapping("/customer/user/queryDeviceDataListByDay")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult queryDeviceDataListByDay(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
                                                   @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
                                                   @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
                                                   @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {
        List<DeviceDataGraphVo> deviceDataGraphVoList = deviceDataService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return ResponseResult.success(deviceDataGraphVoList);
    }


    @GetMapping("/customer/user/queryDeviceDataListByWeek")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult queryDeviceDataListByWeek(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
                                                   @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
                                                   @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
                                                   @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {
        List<DeviceDataGraphVo> deviceDataGraphVoList = deviceDataService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
        return ResponseResult.success(deviceDataGraphVoList);
    }
}
